<template>
  <div class="container pws-login" id="particlesId">
    <div class="login-card animated zoomInDown">
      <div class="logo-header">
        <img src="../../../public/img/logo.png" alt="" />
        <h3>重庆市潼南区农业科技投资(集团)有限公司</h3>
      </div>
      <div class="login-title">
        <div class="login-tl">特作所物联管理平台</div>
      </div>
      <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0" class="login_form" @submit.native.prevent>
        <el-form-item label="" label-width="0" prop="username">
          <el-input class="lang_input" placeholder="请输入您的用户名" prefix-icon="el-icon-user"  clearable v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="" label-width="0" prop="password">
          <el-input class="lang_input" :type="passwordType" placeholder="请输入您的密码" prefix-icon="el-icon-lock" show-password v-model="loginForm.password">
              <i class="el-icon-view el-input__icon" slot="suffix" @click="showPassword"></i>
          </el-input>
        </el-form-item>
        <el-button type="primary" native-type="submit" @click="handleLogin('ruleForm')" class="lang_button" :loading="btnLoading">登 录</el-button>
      </el-form>
    </div>
  </div>
</template>

<script>
import particles from 'particles.js' 
import particlesConfig from '@/util/particles.json'
import { randomLenNum } from "@/util/util";
import { mapGetters } from "vuex";
export default {
  name: 'loginp',
  data () {
    return {
      loginForm: {
        username: "",
        password: "",
      },
      loginRules: {
        username: [
          { required: true, message: "请输入您的用户名", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, message: "密码长度最少为6位", trigger: "blur" }
        ],
      },
      passwordType: "password",
      btnLoading: false,
    }
  },
  created() {

  },
  mounted() {
    particlesJS("particlesId",particlesConfig);
    
  },
  computed: {
    ...mapGetters(["tagWel"])
  },
  methods: {
    // 显示、隐藏 密码
    showPassword() {
      this.passwordType === "text"
        ? (this.passwordType = "password")
        : (this.passwordType = "text");
    },
    // 登录
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.btnLoading = true;
          this.$store.dispatch("LoginByUsername", this.loginForm).then((res) => {
            this.btnLoading = false;
            this.$router.push({ path: '/aintenance/dashboard' });
          }).catch(() => {
            this.btnLoading = false;
          })
        }
      });
    }
   
  }
}
</script>
<style lang="scss">
.pws-login {
  /**表单样式**/
  .login_form {
    margin-top: 40px;
    .el-form-item {
      margin-bottom: 30px;
      & + .el-form-item {
        margin-bottom: 20px;
      }
      .el-input__inner {
        height: 40px;
        line-height: 40px;
      }
      .el-input__icon {
        line-height: 40px;
        font-size: 18px;
      }
    }
  }
  .particles-js-canvas-el {
    position: absolute;
    z-index: 1;
    // pointer-events: none;
  }
}
</style>
<style lang="scss" scoped>
.container {
  height: 100%;
  background-image: url('../../../public/img/bg.png');
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: relative;
}
.login-card {
  width: 525px;
  height: auto;
  background-color: #fff;
  border-radius: 10px;
  padding: 40px;
  box-sizing: border-box;
  position: relative;
  z-index: 2;
}
.login-title {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #00923F;
  .login-tl {
    font-size: 22px;
  }
  .login-tr {
    height: 20px;
    line-height: 20px;
    cursor: pointer;
    img {
      width: 20px;
      height: 20px;
      vertical-align: top;
      margin-right: 5px;
    }
  }
}
.lang_button {
  background-color: #00923F;
  width: 100%;
  padding: 12px 20px;
  margin-top: 20px;
  font-size: 18px;
  border-color: #00923F;
}
.logo-header {
  display: flex;
  align-items: center;
  padding-bottom: 30px;
  margin-bottom: 30px;
  border-bottom: 1px solid #67c13a;
  img {
    width: 70px;
    height: 70px;
    margin-right: 20px;
  }
  h3 {
    color: #00923F;

  }
}
</style>

